package logic

import (
	"context"
	"usershop/good_srv/model/mysql"

	"usershop/good_srv/goods"
	"usershop/good_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsCreateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsCreateLogic {
	return &GoodsCreateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsCreateLogic) GoodsCreate(in *goods.CreateGoodsRequest) (*goods.CreateGoodsResponse, error) {
	// todo: 新增
	g := mysql.Goods{
		GoodsTitle:  in.GoodsTitle,
		GoodsPrice:  in.GoodsPrice,
		GoodsStock:  in.GoodsStock,
		GoodsStatus: in.GoodsStatus,
		GoodsCover:  in.GoodsCover,
	}
	err := g.Create()
	if err != nil {
		logx.Error("商品添加失败", err)
		return nil, err
	}

	return &goods.CreateGoodsResponse{
		GoodsID: int64(g.ID),
	}, nil
}
